package com.pmonitor.servlet;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import weibo4j.Account;
import weibo4j.Users;
import weibo4j.model.User;

import com.pmonitor.operate.UserOperate;
import com.pmonitor.util.SessionUtils;

public class HomeServlet extends BaseServlet {
	/** serialVersionUID.*/
	private static final long serialVersionUID = 979508873283083214L;
	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		doWelcome(req, resp);
	}

	public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		doWelcome(req, resp);
	}

	private void doWelcome(HttpServletRequest req, HttpServletResponse resp) {
		weibo = SessionUtils.getWeibo(req);
		accessToken = SessionUtils.getAccessToken(req);
		try{
			if(weibo!=null&&accessToken!=null){
				Account accountOpt = new Account();
				String uid = accountOpt.getUid().getString("uid");
				UserOperate userOpt = new UserOperate();
				User user = userOpt.showUserById(uid);
				resp.sendRedirect("welcome.html");
			}
			resp.sendRedirect("index.jsp");
		}
		catch(Exception e){
			
		}
	}
}
